<?php
class investigate_data
{
    private $db;
    private $table;

    public function __construct() {
        global $db;
        $this->db = &$db;
        $this->table = DB_PRE.'investigate_record_data';
    }

     /**
		 * 调查问卷记录表单条数据
		 *
		 * @param $id
		 * @return $count
		 */
         function get_count($investigateid = '')
		 {
            $sql = "SELECT count(*) as number FROM $this->table";
            if(!empty($investigateid))
            {
                $sql .= " where investigateid = '$investigateid'";
            }
            $this->db->prepare( $sql );
            $count = $this->db->execute( true );
            return $count;
         }

         /**
		 * 调查问卷记录表查询
		 *
		 * @param $where
		 * @return $result
		 */
		function get_list( $params, $order, $page=1, $pagesize=10 )
		{
            $where = '';
            if( is_array( $params ) && sizeof( $params ) > 0 )
            {
                $where = ' where ';
                $where .= implode( ' and ', $params );
            }
            $where .= $order;
            $this->db->prepare( "SELECT count(*) as nums FROM $this->table" . $where );
            $res = $this->db->execute( true );
            $nums = isset( $res['nums'] ) ? intval( $res['nums'] ) : 0;
            $this->pages = pages( $nums, $page, $pagesize );
            $this->db->prepare( "SELECT * FROM $this->table" . $where . " limit ?, ?" );
            $this->db->set_int( ( $page-1 ) * $pagesize );
            $this->db->set_int( $pagesize );
            $list = $this->db->execute();
            return $list;
		}

        /**
		 * 调查问卷记录表信息添加
		 *
		 * @param $info （提交的表单数组）
		 * @return $res
		 */
         public function add( $info )
        {
            $uuid = $this->db->get_uuid();
            array_push($info,array('id'=>$uuid) );
            $res = $this->db->insert( $this->table, $info );
            return $res;
        }
}
?>
